package com.cj.pj.sys.service.impl;

import com.cj.pj.sys.common.exception.ServiceException;
import com.cj.pj.sys.common.pojo.PageObject;
import com.cj.pj.sys.dao.SysUserDao;
import com.cj.pj.sys.pojo.User;
import com.cj.pj.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    SysUserDao sysUserDao;

    @Override
    public PageObject<User> getPageObject(String username, int pageCurrent) {
        int rowCout=sysUserDao.getPageCount(username);
        if(rowCout==0)throw  new ServiceException("没有查询到任何数据");
        int pageSzie=5;
        int startIndex=(pageCurrent-1)*pageSzie;
        return new PageObject<User>(pageCurrent,sysUserDao.getPageObject(username,startIndex,pageSzie),rowCout);
    }

    @Override
    public String changeValid(int id, int valid) {
        sysUserDao.changeValid(id,valid);
        if(valid==0){
            return "禁止成功";
        }else {
            return "启用成功";
        }
    }

    @Override
    public List<User> findObjectById(Integer id) {
        return sysUserDao.findObjectById(id);
    }
}
